home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / opt / pinstaller / templates / ppcArchitectureTemplate.py < prev    next >
Text File  |  2005-10-15  |  5KB  |  106 lines

  1. """
  2. # Copyright 1999-2005 Gentoo Foundation
  3. # This source code is distributed under the terms of version 2 of the GNU
  4. # General Public License as published by the Free Software Foundation, a copy
  5. # of which can be found in the main directory of this project.
  6. Gentoo Linux Installer
  7.  
  8. $Id: ppcArchitectureTemplate.py,v 1.5 2005/10/15 17:24:46 agaffney Exp $
  9. Copyright 2004 Gentoo Technologies Inc.
  10.  
  11.  
  12. This fills in ppc specific functions.
  13. """
  14.  
  15. import GLIUtility, string
  16. from x86ArchitectureTemplate import x86ArchitectureTemplate
  17. from GLIException import *
  18. import parted
  19.  
  20. class ppcArchitectureTemplate(x86ArchitectureTemplate):
  21.     def __init__(self,configuration=None, install_profile=None, client_controller=None):
  22.         ppcArchitectureTemplate.__init__(self, configuration, install_profile, client_controller)
  23.         self._architecture_name = 'ppc'
  24.  
  25.     
  26.     def install_bootloader(self):
  27.         "Installs and configures bootloader"
  28.         #
  29.         # THIS IS ARCHITECTURE DEPENDANT!!!
  30.         # This is the ppc way.. it uses yaboot for new world.
  31.         
  32.         if self._install_profile.get_boot_loader_pkg() or self._install_profile.get_boot_loader_pkg() == "none":
  33.             exitstatus = self._emerge(self._install_profile.get_boot_loader_pkg())
  34.             if exitstatus != 0:
  35.                 raise GLIException("BootLoaderEmergeError", 'fatal', 'install_bootloader', "Could not emerge bootloader!")
  36.         else:
  37.             pass
  38.         
  39.         if self._install_profile.get_boot_loader_pkg() == "yaboot":
  40.             self._configure_yaboot()
  41.         else:
  42.             raise Exception("BootLoaderError",'fatal','install_bootloader',"Invalid bootloader selected:"+self._install_profile.get_boot_loader_pkg())
  43.  
  44.     def _configure_yaboot(self):
  45.         build_mode = self._install_profile.get_kernel_build_method()
  46.         root_device = ""
  47.         root_minor = ""
  48.         parts = self._install_profile.get_partition_tables()
  49.         for device in parts:
  50.             tmp_partitions = parts[device]
  51.             for partition in tmp_partitions:
  52.                 mountpoint = tmp_partitions[partition]['mountpoint']
  53.                 if mountpoint == "/":
  54.                     root_minor = str(int(tmp_partitions[partition]['minor']))
  55.                     root_device = device
  56.         if self._install_profile.get_bootloader_kernel_args(): bootloader_kernel_args = self._install_profile.get_bootloader_kernel_args()
  57.         else: bootloader_kernel_args = ""
  58.         #Assuming the config program works as specified, it should do the majority of the work.
  59.         #this is the white rabbit object.  antarus: it expects a full fstab, /proc mounted, and a kernel in /boot/vmlinux.  The manaul also says /dev must be bind-mounted.
  60.         exitstatus = GLIUtility.spawn("yabootconfig --chroot "+self._chroot_dir+" --quiet", display_on_tty8=True)
  61.         if not GLIUtility.exitsuccess(exitstatus):
  62.             raise GLIException("YabootError",'fatal','_configure_yaboot',"Could not successfully run the yabootconfig command.")
  63.         #Hopefully now an /etc/yaboot.conf exists but does not have the correct kernel/Sysmap information.
  64.         #We must gather that info like we have done for the other bootloaders.
  65.         file_name = self._chroot_dir + "/boot/kernel_name"
  66.         file_name2 = self._chroot_dir + "/boot/initrd_name"
  67.         exitstatus2 = GLIUtility.spawn("ls "+root+"/boot/kernel-* > "+file_name)
  68.         if build_mode == "genkernel":
  69.             exitstatus3 = GLIUtility.spawn("ls "+root+"/boot/initramfs-* > "+file_name2)
  70.         else:
  71.             exitstatus3 = GLIUtility.spawn("touch "+file_name2)
  72.         if (exitstatus2 != 0) or (exitstatus3 != 0):
  73.             raise GLIException("BootloaderError", 'fatal', '_configure_yaboot', "Error in one of THE TWO run commands")
  74.         self._logger.log("Bootloader: the three information gathering commands have been run")
  75.         g = open(file_name)
  76.         h = open(file_name2)
  77.         initrd_name = h.readlines()
  78.         kernel_name = g.readlines()
  79.         g.close()
  80.         h.close()
  81.         if not kernel_name[0]:
  82.             raise GLIException("BootloaderError", 'fatal', '_configure_yaboot',"Error: We have no kernel in /boot to put in the yaboot.conf file!")
  83.         kernel_name = map(string.strip, kernel_name)
  84.         initrd_name = map(string.strip, initrd_name)
  85.         for i in range(len(kernel_name)):
  86.             kernel_name = kernel_name[i].split(root)[1]
  87.         for i in range(len(initrd_name)):
  88.             initrd_name = initrd_name[i].split(root)[1]
  89.         #Open the file and edit the right lines
  90.         f = open(self._chroot_dir+"/etc/yaboot.conf")
  91.         contents = f.readlines()
  92.         f.close()
  93.         for i in range(0, len(contents)):
  94.             if contents[i] == "image=/boot/vmlinux":
  95.                 contents[i] = "image=/boot/"+kernel_name[5:]
  96.                 if build_mode == "genkernel":
  97.                     #insert /dev/ram0 line
  98.                     contents.insert("root=/dev/ram0",i+2)
  99.                     #insert partition line.
  100.                     contents.insert("partition="+root_minor,i+3)
  101.                     #edit append line. use root_device and root_minor.
  102.                     contents.insert("append=\"real_root="+root_device+root_minor+ " init=/linuxrc "+bootloader_kernel_args + "\" \n", i+4)
  103.         f = open(self._chroot_dir+"/etc/yaboot.conf",'w')
  104.         f.writelines(contents)
  105.         f.close()
  106.